<!DOCTYPE html>
<html>
<head>
    <include file="./Application/Home/View/Tpl/head.html" />
</head>
<body  class="fixed-header theme-blue-gradient">
<div   id="theme-wrapper">
    <include file="./Application/Home/View/Tpl/header.html" />

    <div id="page-wrapper" class="container">
        <div class="row">
            <include file="./Application/Home/View/Tpl/menu.html"/>

            <div id="content-wrapper">
                <BR>
                <div class="row">
                    <include file="./Application/Home/View/Tpl/alert.html"/>

                    <div class="row">
                        <div class="alert alert-info alert-dismissable">
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                            <h4><strong>取证配置操作方法</strong></h4>
                            <p>先点我
                                <a href="#" data-toggle="modal" data-target="#modal-addTroy" class="btn btn-success">上传取证文件</a>
                                ，取证文件只支持apk和exe。
                            </p>
                        </div>
                    </div>
                    <div class="row">
                        <div class="focusPersonWrap">
                            <div class="panel">
                                <div class="panel-heading">
		                            	<span class="panel-icon">
			                              	<i class="imoon imoon-table2"></i>
			                            </span>
                                    <span class="panel-title">取证文件配置管理</span>
                                    <div class="widget-menu pull-right mr10" data-step="1" data-intro="点击按钮，可上传取证文件" data-position='right'>
                                        <div class="btn-group">
                                            <a href="#" data-toggle="modal" data-target="#modal-addTroy" class="btn btn-sm  btn-success btnaddTroy"><i class="glyphicon glyphicon-plus"></i>上传取证文件
                                            </a>
                                        </div>
                                    </div>
                                </div>
                                <div class="panel-body pn">
                                    <div class="deviceList">
                                        <table id="troyTable" class="table table-striped table-bordered" cellspacing="0" width="100%" data-step="3" data-position='top'>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <include file="./Application/Home/View/Tpl/footer.html"/>

            </div>
        </div>

    </div>


    <!--上传取证文件    start-->
    <div class="modal fade bs-example-modal-lg" id="modal-addTroy" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <form id="addTroy" role="form">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title">上传取证文件</h4>
                    </div>
                    <div class="modal-body">
                        <div class="admin-form clearfix">

                            <div class="section mb10 col-md-6">
                                <label for="troyname" class="field-label text-center pull-left lh40">取证文件名称：</label>
                                <div class="col-md-8">
                                    <label for="troyname" class="field">
                                        <input type="text" name="troyname" id="troyname" class="form-control" placeholder="取证文件名称">
                                    </label>
                                </div>
                            </div>
                            <div class="section mb10 col-md-6">
                                <label for="troyversion" class="field-label text-center pull-left lh40" >取证文件版本号：</label>
                                <div class="col-md-8">
                                    <label for="troyversion" class="field">
                                        <input type="text" name="troyversion" id="troyversion" class="form-control"  placeholder="取证文件版本号">
                                    </label>
                                </div>
                            </div>
                            <div class="section mb10 col-md-12">
                                <label for="troydesc" class="field-label text-center pull-left lh40">取证文件描述：</label>
                                <div class="col-md-10">
                                    <label for="troydesc" class="field">
                                        <input type="text" name="troydesc" id="troydesc" class="form-control" value="" placeholder="取证文件描述">
                                    </label>
                                </div>
                            </div>
                            <div class="section mb10 col-md-12">
                                <label for="troyfile" class="field-label text-center pull-left lh40">上传取证文件：</label>
                                <div class="col-md-10">
                                    <label for="troyfile" class="field">
                                        <input type="file" class="gui-file" name="image" id="image"  onchange='$("#troyfile").val($(this)[0].files[0].name);'>
                                        <input type="text"  class="hidden" id="troyfile" placeholder=" ">


                                    </label>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default"data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-primary">上传取证文件</button>
                    </div>
                </div><!-- /.modal-content -->
            </form>
        </div><!-- /.modal-dialog -->
    </div>
    <!--上传取证文件    end-->





</div>
<!-- ./wrapper -->

<include file="./Application/Home/View/Tpl/commjs.html" />

<script src="__PUBLIC__/js/modernizr.js"></script>
<script src="__PUBLIC__/datatable/datatables.min.js"></script>
<script src="__PUBLIC__/datatable/dataTables.bootstrap.js"></script>
<script src="__PUBLIC__/plugins/confirm/confirm.js"></script>
<!-- PNotify -->
<script src="__PUBLIC__/plugins/pnotify/pnotify.js"></script>
<script>
    $(document).ready(function () {
        getAllTroy();
        //操作提示信息
        function Msg(flag,text){
            if(flag){
                new PNotify({
                    title: '提示信息',
                    text: text,
                    shadow: true,
                    opacity: 1,
                    addclass: 'stack_top_right',
                    type: 'success',
                    stack: {
                        "dir1": "down",
                        "dir2": "left",
                        "push": "top",
                        "spacing1": 10,
                        "spacing2": 10
                    },
                    width: '400px',
                    delay: 3000
                });
            }else{
                new PNotify({
                    title: '提示信息',
                    text: text,
                    shadow: true,
                    opacity: 1,
                    addclass: 'stack_top_right',
                    type: 'danger',
                    stack: {
                        "dir1": "down",
                        "dir2": "left",
                        "push": "top",
                        "spacing1": 10,
                        "spacing2": 10
                    },
                    width: '400px',
                    delay: 3000
                });
            }
        }
        //获取所有取证文件
        function getAllTroy(){
            var table = $('#troyTable').DataTable({
                serverSide: true,
                "ajax": {
                    "url": "{:U('/Home/TrojanIssued/getTroyList','',false)}",
                    "type":"post",
                    "dataSrc": function ( d ) {
                        return d.data;
                    }
                },
                ordering: false,
                "bDestroy": true,
                bLengthChange: false,
                "bAutoWidth": false,
                "pagingType": "scrolling",
                "bInfo": false,
                paging: true,
                pageLength: 10,
                language: {
                    search: '<span class="label bg-primary" data-step="2" data-position="right" style="background-color: #5ccdde !important;padding:4px;">搜索</span>',//右上角的搜索文本，可以写html标签
                    paginate: {
                        previous: "上一页",
                        next: "下一页",
                        first: "首页",
                        last: "尾页"
                    },
                    zeroRecords: "没有内容",
                    infoEmpty: "0条记录",
                },
                pagingType: "full_numbers",//分页样式的类型devicemac
                "aoColumns": [
                    { "sTitle":"取证文件名称", "data": "troyname"},
                    { "sTitle":"取证文件描述", "data":"troydesc"},
                    {"sTitle":"版本号","data":"troyversion"},
                    { "sTitle":"操作", "data": null},
                ],

                "aoColumnDefs":[
                    {
                        "aTargets": 0,
                        "mRender": function (data, type,row) {
                            return '<span troyid="'+row.id+'">'+row.troyname+'</span>';
                        }
                    },
                    {
                        "aTargets": 3,
                        "mRender": function (data, type,row) {
                            return '<a href="#" class="btndelTroy glyphicon glyphicon-trash ml5 btn btn-danger btn-xs"></a>'
                        }
                    }
                ],
                "fnDrawCallback": function ( oSettings ) {
                    $('.btndelTroy').on('click',function(){
                        //获取该行
                        var row = $(this).parent().parent();
                        var troyid = $(this).parent().parent().children().first().children('span').attr('troyid');

                        delTroy(troyid,row);
                    });

                    $('#modal-addTroy').on('shown.bs.modal', function () {
                        $('input').val('');
                    });
                }
            });
        }
        //删除取证文件
        function delTroy(troyid,row){
            Confirm.show('提示信息', '确定要删除吗？', {
                '删除': {
                    'primary': true,
                    'callback': function() {
                        Confirm.hide();
                        $.ajax({
                            url: "{:U('/Home/TrojanIssued/delTroyByNo','',false)}",
                            type: "post",
                            dataType: "json",
                            data:{"id":troyid},
                            success:function(result){
                                row.remove();
                                var flag = result.data;
                                var text = flag?'删除取证文件成功':'删除取证文件失败';
                                Msg(flag,text);
                            },
                            error: function (msg) {
                                //console.log(msg);
                            }
                        })
                    }
                }
            });

        }


        //对form表单赋值
        $.fn.formEdit = function(data){
            return this.each(function(){
                var input, name,option;
                if(data == null){this.reset(); return; }
                for(var i = 0; i < this.length; i++){
                    input = this.elements[i];
                    //checkbox的name可能是name[]数组形式
                    name = (input.type == "checkbox")? input.name.replace(/(.+)\[\]$/, "$1") : input.name;
                    if(data[name] == undefined) continue;
                    switch(input.type){
                        case "checkbox":
                            if(data[name] == ""){
                                input.checked = false;
                            }else{
                                //数组查找元素
                                if(data[name].indexOf(input.value) > -1){
                                    input.checked = true;
                                }else{
                                    input.checked = false;
                                }
                            }
                            break;
                        case "radio":
                            if(data[name] == ""){
                                input.checked = false;
                            }else if(input.value == data[name]){
                                input.checked = true;
                            }
                            break;
                        case "select-one":
                            input.childNodes[1].value =data.caseid;
                            input.childNodes[1].text =data[name];
                            break;
                        case "button":
                            break;
                        default: input.value = data[name];
                    }

                }
            });
        };


        //上传取证文件
        $("#addTroy").validate({
            rules:{
                troyname:{
                    required:true,
                    maxlength:20
                },
                troyversion:{
                    required:true,
                },
                troyfile:{
                    required:true
                },
                troydesc:{
                    required:true
                }
            },
            messages: {
                troyname: {
                    required:'请输入取证文件名称'
                },
                troyversion: {
                    required:'请输入取证文件版本号'
                },
                troyfile: {
                    required:'请上传取证文件'
                },
                troydesc: {
                    required: '请输入取证文件描述'
                }
            },
            errorPlacement: function(error, element) {
                error.appendTo(element.parent().parent());
            },
            submitHandler: function(form) {  //通过之后回调
                var troyname = $("#troyname").val();
                $.ajax({
                    url: "{:U('/Home/TrojanIssued/getTroyByName','',false)}",
                    type: "post",
                    dataType: "json",
                    data:{"troyname":troyname},
                    success:function(result){
                        data = result.data? result.data:"";
                        if(data.length>0){
                            var flag = true;
                            var text = flag?'该取证文件已存在,请重新添加':'';
                            Msg(flag,text);
                        }else{
                            var param = $("#addTroy").serializeArray();
                            var formData = new FormData($( "#addTroy" )[0]);

                            $.ajax({
                                url: "{:U('/Home/TrojanIssued/addTroy','',false)}",
                                type: "post",
                                async: false,
                                cache: false,
                                contentType: false,
                                processData: false,
                                //dataType: "json",
                                data: formData,
                                success: function (result) {
                                    var flag = result.data;
                                    flag?$("#modal-addTroy").modal('hide'):"";
                                    var text = flag?'添加取证文件成功':result.info;
                                    Msg(flag,text);
                                    if(flag){
                                        setTimeout(function () {
                                            window.location.reload();
                                        },1000)
                                    }
                                },
                                error: function (msg) {
                                    //console.log(msg);
                                }
                            });
                        }
                    },
                    error: function (msg) {
                        //console.log(msg);
                    }
                })

            },
            invalidHandler: function(form, validator) {  //不通过回调
                return false;
            }
        });
    });
</script>

</body>
</html>


